
		var mycolumns = [[
    		{field:'name',title:'属性名称',width:100,sortable:true},
   		    {field:'value',title:'属性值',width:100,resizable:false}
        ]];

function formatProgress(value){
    	if (value){
	    	var s = '<div style="width:100%;border:1px solid #ccc">' +
	    			'<div style="width:' + value + '%;background:#cc0000;color:#fff">' + value + '%' + '</div>'
	    			'</div>';
	    	return s;
    	} else {
	    	return '';
    	}
	}
	var editingId;
	function edit(){
		if (editingId != undefined){
			$('#tg').treegrid('select', editingId);
			return;
		}
		var row = $('#tg').treegrid('getSelected');
		if (row){
			editingId = row.id
			$('#tg').treegrid('beginEdit', editingId);
		}
	}
	function save(){
		if (editingId != undefined){
			var t = $('#tg');
			t.treegrid('endEdit', editingId);
			editingId = undefined;
			var persons = 0;
			var rows = t.treegrid('getChildren');
			for(var i=0; i<rows.length; i++){
				var p = parseInt(rows[i].persons);
				if (!isNaN(p)){
					persons += p;
				}
			}
			var frow = t.treegrid('getFooterRows')[0];
			frow.persons = persons;
			t.treegrid('reloadFooter');
		}
	}
	function cancel(){
		if (editingId != undefined){
			$('#tg').treegrid('cancelEdit', editingId);
			editingId = undefined;
		}
	}
	
	function append(){
		
		var obj = $('#tg') ;
		var row = obj.treegrid('getSelected');
		if(row){
			obj.treegrid("append",{
					parent:row.id ,
					data:[{
						id:id++,
						name:"new record"
						}]
				})	;
				//$('#tg').treegrid('beginEdit', 33);
				//$('#tg').treegrid('acceptChanges', 33);
				
			//obj.treegrid('endEdit', editingId);
			}
	}

function clickRow(rowData){
	//alert(index) ;
	if(editingId){
		$('#tg').treegrid('acceptChanges');
		$('#tg').treegrid('endEdit', editingId);
		
		//datagrid.datagrid('endEdit', index);
		editingId=undefined ;
		
	}
	var row = $('#tg').treegrid('getSelected');
	editingId=row.id ;
	$('#tg').treegrid('beginEdit',
							editingId);
	var arrEditor = $('#tg').treegrid("getEditors",editingId) ;
	jQuery.each(arrEditor,function(index,editor){
		var target = $(editor.target) ;
		if (editor.type=="combobox") {
			target.combobox("loadData",JSON.parse('[{"name":"combobox","value":"combobox"}]'));
			target.combobox({onSelect:function (record) {
				if(record.value=="combobox"){
					//alert(record.value) ;
					$("#pgd").propertygrid({url:'../treegrid/combobox_prop.json'});
				}
			}});
		}
	});
	
}
	
var id = 44 ;
function insert(){
	var obj = $('#tg') ;
	var arrRow = obj.treegrid("getRoots");
	var len = arrRow.length ;
	if(len==0){
		obj.treegrid("append",{
					data:[{
						id:id++,
						name:"new record"
					}]
				})	;
	}else{
		obj.treegrid("insert",{
			after : arrRow[len-1].id,
			data:{
				id:id++
			}
		});
	}
}

function generatePage(){
	try{
		var treegrid = $("#tg") ;
		var arrRoot = treegrid.treegrid("getRoots");
		var buffer = generate(arrRoot) ;
		//document.write
		document.write(buffer);
	}catch(e){
		alert(e) ;
	}
	
}

function generate(arrRoot,parent){
	var len = arrRoot.length ;
  var buffer = "" ;
	if(len>0){
			for (var index=0 ;index<len ;index++){
				if(parent && arrRoot[index]._parentId!=parent.id){
					continue ;
				}
				buffer+="<field";
				var columns = $("#tg").treegrid("getColumnFields") ;
				for (var pos=0 ,size=columns.length;pos<size;pos++){
					if(arrRoot[index][columns[pos]]){
						buffer+=" "+columns[pos]+"=\""+arrRoot[index][columns[pos]] +"\"";
					}
				}
				buffer+=">" ;
				var children = $("#tg").treegrid("getChildren",arrRoot[index].id) ;
				var tmp=generate(children,arrRoot[index]) ;
			 	if(tmp){
			 		buffer+=tmp ;
				}
				buffer+="<field/>";
			}
	}
	return buffer ;
}

function getDataOptions(type){
	var dataOptions ="" ;
	switch (type) {
		case "datebox":
			 dataOptions=""
		break;
		default:
			// default statements
	}
	
}

$.extend($.fn.datagrid.defaults.editors, {  
    button: {  
        init: function(container, options){  
            var input = $('<td width="100%"><input type="text"><input type="button" name="..."></td>').appendTo(container);  
            return input;  
        },  
        getValue: function(target){  
              
        },  
        setValue: function(target, value){  
           
        },  
        resize: function(target, width){  
            
        }  
    }  
});